#include <time.h>

#define BUFF_STEP 256

#define S_RWALL S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH

struct versionInfo
{
	struct inf
	{ 
		int 	version;
		time_t 	committed;
		char 	locked;
		int	msg_size;
		int	usr_size;
		int 	lock_usr_size;
	} inf;
	char *userName;
	char *lockUser;
	char *msg;
};

/* Check if a file has been checked into vc before 
	- fileName is the name of the file in the current directory */
int isFileVersioned(const char *fileName);

/* Check if a file exists */
int fileExists(const char *file);


/* Checks in a file for the first time.
   Creates log file and begins with version 1.
*/
int firstCheckin(const char *fileName);

/* Checks in a new version of file.
   returns 0 if it fails to checkin the file
   returns version number othewise
*/
int checkIn(const char* fileName);

/* Checksout  the latest version of the file
   returns the verion checked out on success
   returns -1 on failure
*/
int checkOut(const char* fileName);

/* Generates a file name which refers to filename in the VC subdir */
char* generateVCName(const char* filename);

/* Generates a file name which is approriate for storring log information into */
char* generateLogName(const char* fileName);

/* Generates a file name suitable for storing the diff between the version */
char* generateVerionPatchName(const char* fileName, int version);

/* Reads text from STDIN until EOF is encountered */
int getLongMessage(char** msg);

/* Reads all the information about the specified version.
  if ver = -1, it reads the latest version.
  returns 1 on success, and 0 on failure
*/
int readVersion(const char *logFile, struct versionInfo *ver, int version);

/* Writes verion info to the end of a log file
   returns 1 on success and 0 on failure.
*/
int writeVersion(const char* logFile, struct versionInfo *ver);

/* Removes last version from the log file */
int removeLastVersion(const char* logFile);

/* Removes a lock from a file */
int removeLock(const char* logFile);

/* Checks if the file is currently locked by the operating user */
int ownLock(const struct versionInfo *ver);

/* Creates a patch file using the UNIX diff utility */
int createPatch(const char* newVersion, const char* oldVersion, const char* patchName);

/* Copies a file from src to dst */
int copyFile(const char* src, const char* dst);

/* Generates a the file of the specified version in ./ */
int getFileVersion(const char *fileName, int version, const char* dst);

/* Prints a complete log of a file to the standard output */
int printLog(const char *fileName);

/* Prints a patch which when applied to v1 will produce v2 */
int printPatch(const char *fileName, int v1, int v2);

/* Returns the latest version number */
int getLatestVersion(const char* fileName);
